#include "FollowToFoodState.h"

#include "AIAgent.h"
#include "AntWorld.h"
#include "ControllablePredator.h"
#include "FoodSearchState.h"
#include "FoodSource.h"
#include "SBFollow.h"
#include "SBFlee.h"
#include "SBSeparation.h"

FollowToFoodState::FollowToFoodState(AIAgent* agent, AIAgent* target, FoodSource* food) : AIState(agent), m_pTarget(target), m_pFood(food)
{
	AntWorld* antWorld = TheAntWorld::Instance(); 
	
	Predator* pred = antWorld->GetRandPredator();
	ControllablePredator* contPred = antWorld->GetControlledPredator();

	m_behaviourMap.insert(BehaviourAndWeight(new SBSeparation(agent, 6), 1.0f));

	m_behaviourMap.insert(BehaviourAndWeight(new SBFlee(agent, pred, 10.0f), 0.75f));
	m_behaviourMap.insert(BehaviourAndWeight(new SBFlee(agent, contPred, 10.0f), 0.75f));

	m_behaviourMap.insert(BehaviourAndWeight(new SBFollow(agent, target, 10.0f), 1.0f));
}

Vec3f FollowToFoodState::Update()
{

	if(m_pFood->IsDepleted())
	{	
		m_pAgent->SetAIState(new FoodSearchState(m_pAgent));
		return Vec3f();
	}
	else
	{
		return SumForces();
	}	

	
}

const char* FollowToFoodState::GetStateName() const
{
	return "FollowToFoodState";
}